<style>
  #febs-reject xm-select {
    min-height: 30px;
    line-height: 30px;
  }

  #febs-reject xm-select > .xm-label .scroll .label-content {
    display: flex;
    padding: 0 30px 0 10px;
  }
</style>
<div class="layui-fluid layui-anim febs-anim" id="febs-reject" lay-title="驳回查询">
  <div class="layui-row febs-container">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-body febs-table-full">
          <form class="layui-form layui-table-form" lay-filter="user-table-form">
            <div class="layui-row">
              <div class="layui-col-md10">
                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label layui-form-label-sm">单据</label>
                    <div class="layui-input-inline">
                      <input type="text" name="orderNo" autocomplete="off" class="layui-input" />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label layui-form-label-sm">送签人员</label>
                    <div class="layui-input-inline">
                      <input type="text" name="sendUserCname" autocomplete="off" class="layui-input" />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label layui-form-label-sm">单据分类</label>
                    <div class="layui-input-inline">
                      <select id="billstdNo" name="billstdNo">
                        <option value=""></option>
                      </select>
                    </div>
                  </div>
                                                      <div class="layui-inline">
                                                          <label class="layui-form-label layui-form-label-sm">驳回日期</label>
                                                          <div class="layui-input-inline">
                                                              <input type="text" name="time" id="reject-signTime" class="layui-input">
                                                          </div>
                                                      </div>
                </div>
              </div>
              <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="queryReject">
                  <i class="layui-icon">&#xe848;</i>
                </div>
                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset">
                  <i class="layui-icon">&#xe79b;</i>
                </div>
                  <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more"
                   shiro:hasAnyPermissions="reject:view,reject:delete"><i class="layui-icon">&#xe875;</i>
                    </div>
              </div>
            </div>
          </form>
          <table lay-filter="rejectTable" lay-data="{id: 'rejectTable'}"></table>
        </div>
      </div>
    </div>
</div>
</div>
<script type="text/html" id="reject-status">
  <span class="layui-badge febs-bg-volcano">驳回</span>
</script>
<script type="text/html" id="reject-option">
  <span shiro:lacksPermission="reject:view,reject:delete">
    <span class="layui-badge-dot febs-bg-orange"></span> 无权限
  </span>
  <a lay-event="rejectDetail" shiro:hasPermission="reject:view"><i class="layui-icon febs-edit-area febs-green"></i>详情</a>
  <!--    <a lay-event="sign" shiro:hasPermission="approvals:sign">-->
  <!--        <i class="layui-icon febs-edit-area febs-red"></i>签核</a>-->
  <!--    <a lay-event="flow" shiro:hasPermission="approvals:view"><i-->
  <!--        class="layui-icon febs-edit-area febs-blue"></i>流程</a>-->
</script>
<script data-th-inline="none" type="text/javascript">
  layui.use(["dropdown", "jquery", "laydate", "form", "table", "febs", "api"], function () {
    let $ = layui.jquery,
      laydate = layui.laydate,
      febs = layui.febs,
      form = layui.form,
      table = layui.table,
      dropdown = layui.dropdown,
      api = layui.api,
      $view = $("#febs-reject"),
      $queryReject = $view.find("#queryReject"),
      $reset = $view.find("#reset"),
      $searchForm = $view.find("form"),
      sortObject = { field: "sendDate", type: null },
      tableIns,
      createTimeFrom,
      createTimeTo;
    febs.get(ctx + "baseflow/getList", null, function (datas) {
      const basestdNoes = datas.data;
      // console.log('basestdNoes',basestdNoes)
      $.each(basestdNoes, function (index, item) {
        $("#billstdNo").append(new Option(item.billstdNo + "-" + item.billstdNm, item.billstdNo)); // 下拉菜单里添加元素
        //重新渲染
        layui.form.render("select");
      });
    });
    form.render();

    initTable();

    laydate.render({
      elem: "#reject-signTime",
      range: true,
      trigger: "click",
    });

    dropdown.render({
      elem: $view.find(".action-more"),
      click: function (name, elem, event) {
        let checkStatus = table.checkStatus("rejectTable");
        sessionStorage.setItem("parameterReject", JSON.stringify(checkStatus.data));
        let orderNos = [];
        layui.each(checkStatus.data, function (key, item) {
          orderNos.push(item.orderNo);
        });

        if (name === "delete") {
          if (!checkStatus.data.length) {
            febs.alert.warn("请选择需要删除驳回数据");
          } else {
            febs.modal.confirm("删除驳回数据", "确定删除该驳回数据？", function () {
              let basestdNos = [];
              layui.each(checkStatus.data, function (key, item) {
                basestdNos.push(item.orderNo);
              });
              rejectDelete(basestdNos.join(","));
            });
          }
        }

      },
      options: [
        {
          name: "delete",
          title: "删除驳回数据",
          perms: "reject:delete"
        }

      ]
    });

    /* 监听行事件*/
    table.on("tool(rejectTable)", function (obj) {
      let data = obj.data,
        layEvent = obj.event;
      console.log(obj.data); //得到当前行数据
      sessionStorage.setItem("parameterDataRejectDetail", JSON.stringify(obj.data));
      if (layEvent === "rejectDetail") {
        //详情
        febs.modal.view("驳回详情", "/approval/approvals/approvalsRejectDetail", {
          area: $(window).width() <= 1080 ? "95%" : "1080px",
          offset: "240px",
        });
      }

    });

    table.on("sort(rejectTable)", function (obj) {
      sortObject = obj;
      tableIns.reload({
        initSort: obj,
        where: $.extend(getQueryParams(), {
          field: obj.field,
          order: obj.type,
        }),
      });
    });

    $queryReject.on("click", function () {
      let params = $.extend(getQueryParams(), { field: sortObject.field, order: sortObject.type });
      tableIns.reload({ where: params, page: { curr: 1 } });
    });
    $reset.on("click", function () {
      $searchForm[0].reset();
      sortObject.type = "null";
      createTimeTo = null;
      createTimeFrom = null;
      tableIns.reload({ where: getQueryParams(true), page: { curr: 1 }, initSort: sortObject });
    });

    function initTable() {
      tableIns = febs.table.init({
        elem: $view.find("table"),
        id: "rejectTable",
        url: ctx + "reject/list",
        parseData: (res) => {
          // console.log(res);
          res.data.rows.forEach((res) => {
            res.classify = api.nameFormate(res.classify);
          });
          return {
            code: 0, //解析接口状态
            data: res.data.rows, //解析数据列表
            count: res.data.total, //解析数据长度
          };
        },
        cols: [
          [
            { type: "checkbox" },
            { field: "rejectId", title: "驳回id", minWidth: 20, hide: true },
            { field: "classify", title: "单据类别", minWidth: 100 },
            { field: "orderNo", title: "单据编号", minWidth: 165 },
            { field: "sendUserCname", title: "送签人员", minWidth: 100 },
            { field: "sendUserNo", title: "送签人员帐号", minWidth: 20, disabled: true, hide: true },
            { field: "toUserCname", title: "签核人员", minWidth: 100 },
            { field: "toUserNo", title: "签核人员帐号", minWidth: 20, disabled: true, hide: true },
            { field: "checkRole", title: "签核角色", minWidth: 100 },
            { field: "content", title: "驳回原因", minWidth: 250 },
            { field: "createDate", title: "驳回日期", minWidth: 180 },
            { title: "状态", templet: "#reject-status", minWidth: 80 },
            { title: "操作", toolbar: "#reject-option", minWidth: 140 },
          ],
        ],
      });
    }

    function getQueryParams(flag) {
      let params = $searchForm.serializeJson();
      let sendDate = params.time;
      if (sendDate) {
        createTimeFrom = sendDate.split(" - ")[0];
        createTimeTo = sendDate.split(" - ")[1];
      }
      params.invalidate_ie_cache = new Date();
      params.createTimeFrom = createTimeFrom;
      params.createTimeTo = createTimeTo;
      return params;
    }

    function rejectDelete(basestdNos) {
      febs.get(ctx + "reject/delete/" + basestdNos, null, function () {
        febs.alert.success("删除流程成功");
        $queryReject.click();
      });
    }

  });
</script>
